<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>客户消费统计</title>
    </head>
    <body>
        <div id="expenditure_form">
        </div>
        <div id="expenditureGrid" class="x-form-item">
        </div>
        <script>
            
            Ext.onReady(function(){
                var fromDate = new Ext.form.DateField({
                    fieldLabel: '日期从',
                    name: 'from_date',
                    id: 'from_date',
                    altFormats: 'Y-m-d',
                    format: 'Y-m-d', //格式化日期
                    //disabledDays: [0,6],	//不让选择周六，周日
                    //disabledDaysText: "周末要休息",
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: false,
                    //emptyText: '请选择...',
                    inputType: '2008-01-01',
                    //applyTo: 'cancel_date',
                    vtype: 'daterange',
                    endDateField: 'to_date',
                    //anchor: '95%',
                    width: 100,
                    value: today
                });
                var toDate = new Ext.form.DateField({
                    fieldLabel: '到',
                    name: 'to_date',
                    id: 'to_date',
                    altFormats: 'Y-m-d',
                    format: 'Y-m-d', //格式化日期
                    //disabledDays: [0,6],	//不让选择周六，周日
                    //disabledDaysText: "周末要休息",
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: false,
                    //emptyText: '请选择...',
                    inputType: '2008-01-01',
                    //applyTo: 'cancel_date2',
                    vtype: 'daterange',
                    startDateField: 'from_date',
                    //anchor: '95%',
                    width: 100,
                    value: today
                });
                
                var queryButton = new Ext.Button({
                    text: '查 询',
                    handler: function(){
                        if (formPanel.form.isValid()) {
                            var from_date = fromDate.getValue().format('Y-m-d');
							var to_date = toDate.getValue().format('Y-m-d');
						    
							ds.baseParams.from_date = from_date;
							ds.baseParams.to_date = to_date;
							ds.reload();
							
                        }else{
							Ext.MessageBox.alert('错误消息', '请将必填项信息录入后再提交.');
						}
                    }
                })
                
                var formPanel = new Ext.form.FormPanel({
                    //baseCls: 'x-plain',
                    labelWidth: 65,
                    width: '100%',
                    frame: true,
					labelAlign: 'right',
                    items: [{
                        layout: 'column',
                        border: false,
                        items: [{
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [fromDate]
                        }, {
                            columnWidth: .25,
                            layout: 'form',
                            border: false,
                            items: [toDate]
                        }, {
                            columnWidth: .5,
                            layout: 'form',
                            border: false,
                            items: [queryButton]
                        }]
                    }]
                });
                formPanel.render('expenditure_form');
                
                var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                    header: 'id',
                    width: 50,
                    dataIndex: 'id',
                    hidden: true
                }, {
                    header: "客户姓名",
                    width: 70,
                    dataIndex: 'name'
                }, {
                    header: "会员卡号",
                    width: 100,
                	sortable: true,
                    dataIndex: 'customer_no'
                }, {
                    header: "类型",
                    width: 70,
                    dataIndex: 'customer_type'
                }, {
                    header: "级别",
                    width: 70,
                    dataIndex: 'customer_level'
                }, {
                    header: "联系人",
                    width: 70,
                    dataIndex: 'linkman'
                }, {
                    header: "联系人电话",
                    width: 100,
                    dataIndex: 'linkman_phone'
                }, {
                    header: "订单数",
                    width: 70,
                	sortable: true,
                    dataIndex: 'order_sum'
                }, {
                    header: "票价总金额",
                    width: 70,
                	sortable: true,
                    dataIndex: 'price_sum'
				}, {
                    header: "税款",
                    width: 70,
                	sortable: true,
                    dataIndex: 'tax_sum'
				}, {
                    header: "附加",
                    width: 70,
                	sortable: true,
                    dataIndex: 'fuel_sum'
				}, {
                    header: "积分",
                    width: 70,
                	sortable: true,
                    dataIndex: 'point_sum'
				}, {
                    header: "返现",
                    width: 70,
                	sortable: true,
                    dataIndex: 'f_sum'
				}, {
                    header: "消费总金额",
                    width: 70,
                	sortable: true,
                    dataIndex: 'expenditure_sum'
					
                }]);
                
                var ds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: "/orders/getExpenditureList"
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root'
                    }, [{
                        name: 'id'
                    }, {
                        name: 'name'
                    }, {
                        name: 'customer_no'
                    }, {
                        name: 'customer_type'
                    }, {
                        name: 'customer_level'
                    }, {
                        name: 'linkman'
                    }, {
                        name: 'linkman_phone'
                    }, {
                        name: 'order_sum'
                    }, {
                        name: 'price_sum'
                    }, {
                        name: 'tax_sum'
                    }, {
                        name: 'fuel_sum'
					}, {
						name: 'f_sum'
					}, {
						name: 'point_sum'
					}, {
						name: 'expenditure_sum'
                    }])
                });
                
                var expenditureGrid = new Ext.grid.GridPanel({
                    el: 'expenditureGrid',
                    ds: ds,
                    cm: cm,
                    loadMask: true,
                    autoWidth: true,
                    collapsible: true,
                    animCollapse: true,
                    height: 500,
                    //frame: true,
                    title: '消费统计'
                });
                
                expenditureGrid.render();
                //ds.load();
            
            })
        </script>
    </body>
</html>
